package com.just.recruitback.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.just.recruitback.entity.Information;
import com.just.recruitback.service.InformationService;
import com.just.recruitback.service.base.IInformationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author : baibaiwucahng
 * @date : 2020/7/5  1:19
 */
@Service
public class InformationServiceImpl implements InformationService {
    @Resource
    private IInformationService iInformationService;

    @Override
    public Information getOne(int userId) {
        QueryWrapper<Information> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return iInformationService.getOne(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(Information information) {
        QueryWrapper<Information> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", information.getUserId());
        iInformationService.remove(queryWrapper);
        iInformationService.save(information);
    }
}
